<?php
$categories = $viewModel->get('categories');
$listNews = $viewModel->get("listNews");
$listSlide = $viewModel->get("listSlide");
$lstCourses = $viewModel->get("lstCount");
$listNewsest = $viewModel->get("newsest");
?>
<div id="leftcol">
    <div id="featurenews">
        <div class="anythingSlider">
            <div class="wrapper">
                <ul>
                    <li>
                        <a><img src="<?php echo PATH_IMAGE . 'banner-1.jpg' ?>" alt="" /></a>
                    </li>
                    <li>
                        <a><img src="<?php echo PATH_IMAGE . 'banner-2.jpg' ?>" alt="" /></a>
                    </li>
                    <li>
                        <a><img src="<?php echo PATH_IMAGE . 'banner-3.jpg' ?>" alt="" /></a>
                    </li>
                    <li>
                        <a><img src="<?php echo PATH_IMAGE . 'banner-4.jpg' ?>" alt="" /></a>
                    </li>
                </ul>
            </div>
        </div> <!-- END AnythingSlider -->
    </div>
    <div class="newsest">
        <h3>Mới cập nhật</h3>
        <br>
        <ul>
            <?php
            if (count($listNewsest)) {
                $max = count($listNewsest);
            } else {
                $max = 10;
            }

            for ($i = 0; $i < $max; $i++) {
                if (strlen($listNewsest[$i]->title) > 50) {
                    if (!strpos($listNewsest[$i]->title, " ", 50)) {
                        //neu chuoi lon >50 ma ko tim thay khoang trong thi tim vi tri khoang trang tu do dai >40
                        $pos = strpos($listNewsest[$i]->title, " ", 40);
                    } else {
                        $pos = strpos($listNewsest[$i]->title, " ", 50);
                    }
                    $subStrTitle = substr($listNewsest[$i]->title, 0, $pos);
                } else {
                    $subStrTitle = $listNewsest[$i]->title;
                }
                echo '<li><a href="' . BASE_URL . 'Home/ViewDetail/' . $listNewsest[$i]->news_id . '">' . $subStrTitle . '...</a></li>';
            }
            ?>
        </ul>
    </div><!-- end newsest-->
    <div class="recentnews" style="overflow: hidden;">


        <?php
        if (count($lstCourses) < 4) {
            $maxCourse = count($lstCourses);
        } else {
            $maxCourse = 4;
        }
        for ($i = 0; $i < $maxCourse; $i++) {
            $imgAlt = Helper::getFirstImage($lstCourses[$i]->body);
            ?>
            <div class="recentbox">
                <a href="<?php echo BASE_URL . 'Home/ViewDetail/'.$lstCourses[$i]->news_id;?>">
                    <img src="<?php echo $imgAlt[0]; ?>" alt="<?php echo $imgAlt[1]; ?>" width='137' height='90'">
                    <span><?php echo $lstCourses[$i]->title; ?></span>
                </a>
            </div>
        <?php } ?>


    </div>
    <div class="leftads">
        <embed height="171px" width="100%" src="<?php echo BASE_URL;?>media/img/banner.swf" style=" padding-top: 5px; padding-bottom: 5px;"> </embed>
    </div><!--end left ads 1 -->
    
    <?php
    foreach ($categories as $category) {
        ?>
        <div class="cat-hotnews">
            <h3 class="giaoduc"><img src="<?php echo BASE_URL . 'media/img/book.png'; ?>" /> 
                <span class="cat-title"><a href="<?php echo BASE_URL . '/Home/ViewsContent/' . $category->category_id ?>"><?php echo $category->category_name; ?></a></span>
            </h3>
            <?php
            if (isset($listNews[$category->category_id][0])) {
                $news = $listNews[$category->category_id][0];
                $imgAlt = Helper::getFirstImage($news->body);
                ?>
                <div class="cat-content">

                    <a href="<?php echo BASE_URL . '/Home/ViewDetail/' . $news->news_id; ?>" ><img src="<?php echo $imgAlt[0]; ?>" alt="<?php echo $imgAlt[1]; ?>"  width="137px" height="90px"/></a>
                    <a href="<?php echo BASE_URL . '/Home/ViewDetail/' . $news->news_id; ?>"><?php echo $news->title; ?></a>
                    <p><?php echo $news->content; ?></p>
                </div>
            <?php } ?>
            <div class="cat-listnews">
                <ul>
                    <?php
                    for ($i = 1; $i <= 3; $i++) {
                        if (isset($listNews[$category->category_id][$i])) {
                            $news = $listNews[$category->category_id][$i];
                           
                            //kiem tra chuoi tieu de > 50
                            if (strlen($news->title) > 50) {
                                if (!strpos($news->title, " ", 50)) {
                                    //neu chuoi lon >50 ma ko tim thay khoang trong thi tim vi tri khoang trang tu do dai >40
                                    $pos = strpos($news->title, " ", 40);
                                } else {
                                    $pos = strpos($news->title, " ", 50);
                                }
                                $shortStr = substr($news->title, 0, $pos);
                            } else {
                                //echo "<50";
                                $shortStr = $news->title;
                            }
                            ?>


                            <li><a href="<?php echo BASE_URL . '/Home/ViewDetail/' . $news->news_id; ?>">
                                    <?php echo $shortStr; ?>...
                                </a></li>
                            <?php
                        }
                    }
                    ?>
                </ul>
            </div>

        </div>
    <?php } ?>
</div><!--end left -->
